package com.senriot.quickup.service.mapper

import com.senriot.cloud.common.IEntityMapper
import com.senriot.quickup.domain.Agency
import com.senriot.quickup.service.dto.AgencyDTO
import org.mapstruct.Mapper
import org.mapstruct.Mapping
import org.mapstruct.Mappings
import org.mapstruct.NullValuePropertyMappingStrategy

@Mapper(
    componentModel = "spring",
    uses = [CityMapper::class, UserMapper::class],
    nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE
)
abstract class AgencyMapper : IEntityMapper<AgencyDTO, Agency>
{
    fun fromId(id: Long?) = id?.let { Agency().apply { this.id = it } }

    @Mappings(
        Mapping(target = "cityId", source = "city.id"),
        Mapping(target = "provinceId", source = "province.id"),
        Mapping(target = "districtId", source = "district.id"),
        Mapping(target = "cityName", source = "city.name"),
        Mapping(target = "provinceName", source = "province.name"),
        Mapping(target = "accountId", source = "account.id"),
        Mapping(target = "accountName", source = "account.nickName")
    )
    abstract override fun toDto(entity: Agency): AgencyDTO


    @Mappings(
        Mapping(target = "city", source = "cityId"),
        Mapping(target = "province", source = "provinceId"),
        Mapping(target = "district", source = "districtId"),
        Mapping(target = "account", source = "accountId")
    )
    abstract override fun toEntity(dto: AgencyDTO): Agency


}
